from configparser import ConfigParser
import os
import json


logpath = '/home/spd/datasets/road/log'
if not os.path.isdir(logpath):
    os.makedirs(logpath)

cfg_file = f'/home/spd/Projects/road/cfg/config.ini'
config = ConfigParser()
config.read(cfg_file)

# default
deviceid = config['default'].getint('deviceid')
gps_run = config['default'].getboolean('gps_run')
videos_run = config['default'].getboolean('videos_run')
lonlat = config['default'].getboolean('lonlat')

# input
# cameras_ = config['input'].get('cameras').strip().split(',')
cameras = json.loads(config['input'].get('cameras').strip())
camerasIdx = config['input'].get('cameraIds').strip().split(',')
camerasIdx = [idx.strip() for idx in camerasIdx]

# output
post_baseImage = config['output'].getboolean('post_baseImage')
picApi_url = config['output'].get('picApi_url')
gpsApi_url = config['output'].get('gpsApi_url')
appkey = config['output'].get('appkey')
secret = config['output'].get('secret')


gps_postIntervalTime = config['output'].getint('gps_postIntervalTime')
result_postIntervalTime = config['output'].getint('result_postIntervalTime')
record_fps = config['output'].getfloat('record_fps')
speed_thresh = config['output'].getfloat('speed_thresh')
con_times = config['output'].getint('con_times')
height_offset = config['output'].getfloat('height_offset')

# net
config_file = config['net'].get('config_file')
data_file = config['net'].get('data_file')
weights = config['net'].get('weights')
result_path = config['net'].get('result_path')

for fdir in ['images', 'data']:
    redir = os.path.join(result_path, fdir)
    if not os.path.isdir(redir):
        os.mkdir(redir)

backup_path = config['net'].get('backup_path')
if not os.path.isdir(backup_path):
    os.mkdir(backup_path)

for bdir in ['images', 'data', 'gps']:
    bkdir = os.path.join(backup_path, bdir)
    if not os.path.isdir(bkdir):
        os.mkdir(bkdir)

ths = config['net'].get('threshes').split(',')
threshes = [float(th.strip()) for th in ths]
object_detection = config['net'].getboolean('object_detection')
w_thresh = config['net'].getint('w_thresh')
h_thresh = config['net'].getint('h_thresh')
sky_thresh = config['net'].getfloat('sky_thresh')
